<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class CommentController extends Controller
{
    /**
     * 获取评论
     * @return mixed
     */
    public function getComment(){
        if($id=Input::except('_token')){
            $comments=DB::table('comment')->select('comment.comment','comment.created_at','comment.id',
                'comment.like','user.username','user.avatar')
                ->join('user','user.id','=','uid','left')->where('comment.cid',$id)
                ->get();
            return $comments;
        }
    }

    /**
     * 更改评论
     * @return array
     */
    public function updateComment(){
        if($input=Input::except('_token')){
            return (bool)DB::table('comment')->where(['id'=>$input['id']])->update(['comment'=>$input['comment']])?
            ['status'=>1,'msg'=>'更改成功']:['status'=>0,'msg'=>'更改失败'];
        }
    }

    /**
     * 删除评论
     * @return array
     */
    public function deleteComment(){
        if($id=Input::except('_token')){
            return DB::table('comment')->where(['id'=>$id])->delete()?
                ['status'=>1,'msg'=>'删除成功']:['status'=>0,'msg'=>'删除失败'];
        }
    }
}
